package com.example.cinema.bindingdata;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.databinding.library.baseAdapters.BR;


import java.util.List;

public class CircleListAdapter<T> extends BaseAdapter {

    private List<T> data;
    private Context context;
    private LayoutInflater layoutInflater;
    private int layoutid;

    public CircleListAdapter(List<T> data, Context context,int layoutid) {
        this.data = data;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.layoutid = layoutid;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private FuYong fu;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null)
        {
            ViewDataBinding viewDataBinding = DataBindingUtil.inflate(layoutInflater,layoutid,parent,false);
            convertView = viewDataBinding.getRoot();
            fu = new FuYong();
            fu.dataBinding = viewDataBinding;
            convertView.setTag(fu);
        }else {
            fu = (FuYong) convertView.getTag();
            fu.dataBinding.setVariable(BR.blansdata,data.get(position));
        }

        return convertView;
    }

    class FuYong
    {
        ViewDataBinding dataBinding;
    }
}
